--
-- Author: shunguo.chen
-- Date: 2019-04-03 11:17:54
--
-- ReconnectDialog 重连的dialog
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.DialogBase)

local DISABLE_TIME_ARY = {2,5,10}

function ClassRef:addClickEvent()
    self._confirmNum = 1

    if not self._okBtn then return end
    self._okBtn:addClickEventListener(function(sender)
        self._confirmNum = self._confirmNum + 1
        if self._confirmNum < 6 then
            executeFunc(self._onConfirm)
        else
            -- 5次重连后移除界面调用取消回调
            executeFunc(self._onCancel)
            if not cc.isDead( self ) then
                self:removeFromParent()
            end
        end
    end)

    if not self._cancelBtn then return end
    if self._onCancel then
        self._cancelBtn:addClickEventListener(function(sender)
            executeFunc(self._onCancel)
            if not cc.isDead( self ) then
                self:removeFromParent()
            end
        end)
    else
        self._cancelBtn:setVisible(false)
        self._okBtn:setPositionX(self._ui.bg:getPositionX())
    end
end

function ClassRef:refreshConfirmBtn()
    if self._okBtn then
        display.stopBtnTimeout(self._okBtn)

        local timeout = DISABLE_TIME_ARY[self._confirmNum] or DISABLE_TIME_ARY[#DISABLE_TIME_ARY]
        if timeout > 0 then
            display.setBtnTimeout(self._okBtn, timeout)
        end
    end
end

return ClassRef